package com.md.mod.utils;

import com.github.pagehelper.Page;

/**
 * ********************************
 *
 * @author zhaoqingwei.
 * 天下英雄出我辈，一入江湖岁月催.
 * 20192019/1/2620:05
 * ********************************
 * 描述：
 * <p>
 * 注释：
 * status 状态
 * msg 描述
 * obj 数据
 * ok 操作成功
 * no 操作失败
 * desc 描述
 **/
public class JSONResult {

    private Integer status;

    private String msg;

    private Object obj;

    private String isok;

    private String desc;

    private Page page;

    public JSONResult() {
    }
    /**
     *
     * @param status
     * @param msg
     * @param obj
     */
    public JSONResult(Integer status, String msg, Object obj,Page page,String desc) {
        this.status = status;
        this.msg = msg;
        this.obj = obj;
        this.page = page;
        this.desc = desc;
    }
    /**
     *
     * @param status
     * @param msg
     * @param obj
     */
    public JSONResult(Integer status, String msg, Object obj,String desc) {
        this.status = status;
        this.msg = msg;
        this.obj = obj;
        this.desc = desc;
    }

    public JSONResult(Integer status, String msg, Object obj) {
        this.status = status;
        this.msg = msg;
        this.obj = obj;
    }

    /**
     *
     * @param status
     * @param msg
     * @param desc
     */
    public JSONResult(Integer status, String msg,String desc) {
        this.status = status;
        this.msg = msg;
        this.desc = desc;
    }

    /**
     *
     * @param status
     * @param msg
     */
    public JSONResult(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    /**
     *
     * @param isok
     * @param desc
     */
    public JSONResult(String isok,String desc) {
        this.isok = isok;
        this.desc = desc;
    }

    /**
     *
     * @param isok
     */
    public JSONResult(String isok) {
        this.isok = isok;
    }

    /**
     * 带数据封装
     * @param status
     * @param msg
     * @param obj
     * @return
     */
    public static JSONResult result(Integer status, String msg, Object obj){

        return new JSONResult(status, msg, obj);
    }

    /**
     * 不带数据封装
     * @param status
     * @param msg
     * @return
     */
    public static JSONResult result(Integer status, String msg){

        return new JSONResult(status, msg);
    }

    /**
     * 操作成功
     * @param
     * @return
     */
    public static JSONResult ok(Object O){
        return new JSONResult(StatusUtils.OK.getIndex(),StatusUtils.OK.getValue(),O,StatusUtils.OK.getDesc());
    }

    /**
     * 操作失败
     * @param
     */
    public static JSONResult no(){

        return new JSONResult(StatusUtils.NO.getValue(),StatusUtils.NO.getDesc());
    }

    /**
     * Ajax异常处理
     * @param e
     * @return
     */
    public static JSONResult commonAjaxException(Exception e){

        return new JSONResult(StatusUtils.HTTP500.getIndex(), StatusUtils.HTTP500.getValue(), e.getMessage(),StatusUtils.HTTP500.getDesc());
    }

    /**
     * 分页列表查询返回数据规范
     * @param o
     * @param page
     * @return
     */
    public static JSONResult JSONPage(Object o,Page page){

        return new JSONResult(StatusUtils.OK.getIndex(), StatusUtils.OK.getValue(), o,page,StatusUtils.OK.getDesc());
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getObj() {
        return obj;
    }

    public void setObj(Object obj) {
        this.obj = obj;
    }

    public String getIsok() {
        return isok;
    }

    public void setIsok(String isok) {
        this.isok = isok;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

    @Override
    public String toString() {
        return "JSONResult{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", obj=" + obj +
                ", isok='" + isok + '\'' +
                ", desc='" + desc + '\'' +
                ", page=" + page +
                '}';
    }
}
